﻿<cfsilent>
	<cfscript>
		
		propAdvice = getProperty("serviceFactory").getBean("turnPropertyAdvice");
		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		
		response = structNew();
		
		transaction {
		
			sql = "	SELECT
						ct.turn_prop
					FROM
						t_choose_turn ct
					WHERE
						ct.ct = :ct ";
			
			queryObj = new Query(datasource = application.dnsMaster);
			queryObj.addParam(name = "ct", value = event.getArg("CT"), cfsqltype = "cf_sql_char");
			rs_turnEntity = queryObj.execute(sql = sql).getResult();
			
			propAdvice.parseProperty( rs_turnEntity.turn_prop );
		
			switch ( event.getArg('prop' )) {
				
				case "Running":
					/* 该轮次是否可用 */
					if ( yesNoFormat(event.getArg('status')) ) {
						propAdvice.setRunning( true );
					}
					else {
						propAdvice.setRunning( false );
					}

					/* 正向检测 只要轮次设为禁用 则任何用途都非法 */
					if ( not propAdvice.getRunning() ) {

						propAdvice.setProgramTask( false ); 
						propAdvice.setCommonTask( false );
						propAdvice.setRetaking( false );
		
						propAdvice.setAssist( false );
						propAdvice.setSecondary( false );
						
						propAdvice.setFixUp( false );
						propAdvice.setEarlyGraduate( false );
		
						propAdvice.setSport( false );
						
					}
					
					break;
					
				/* 反向检测 开放任意选课 如果当前轮次是禁用状态 则取消禁用标志 */
				case "ProgramTask":
				
					/* 是否开放计划课程选课 */
					if ( yesNoFormat(event.getArg('status')) ) {
						propAdvice.setProgramTask( true );
					}
					else {
						propAdvice.setProgramTask( false );
					}
					
					if ( propAdvice.getProgramTask() ) { propAdvice.setRunning( true ); }
					break;

				case "CommonTask":
				
					/* 是否开放全校通选课选课 */
					if ( yesNoFormat(event.getArg('status')) ) {
						propAdvice.setCommonTask( true );
					}
					else {
						propAdvice.setCommonTask( false );
					}
					
					if ( propAdvice.getCommonTask() ) { propAdvice.setRunning( true ); }
					break;

				case "Retaking":
					
					/* 是否开放重修选课 */
					if ( yesNoFormat(event.getArg('status')) ) {
						propAdvice.setRetaking( true );
					}
					else {
						propAdvice.setRetaking( false );
					}
					
					if ( propAdvice.getRetaking() ) { propAdvice.setRunning( true ); }
					break;
				
				case "FixUp":
					
					/* 是否开放补修选课 */
					if ( yesNoFormat(event.getArg('status')) ) {
						propAdvice.setFixUp( true );
					}
					else {
						propAdvice.setFixUp( false );
					}
					
					if ( propAdvice.getFixUp() ) { propAdvice.setRunning( true ); }
					break;

				case "Assist":
					
					/* 是否开放辅修选课 */
					if ( yesNoFormat(event.getArg('status')) ) {
						propAdvice.setAssist( true );
					}
					else {
						propAdvice.setAssist( false );
					}
					
					if ( propAdvice.getAssist() ) { propAdvice.setRunning( true ); }
					break;

				case "Secondary":
					
					/* 是否开放双学位选课 */
					if ( yesNoFormat(event.getArg('status')) ) {
						propAdvice.setSecondary( true );
					}
					else {
						propAdvice.setSecondary( false );
					}
					
					if ( propAdvice.getSecondary() ) { propAdvice.setRunning( true ); }
					break;
					
				case "EarlyGraduate":
					
					/* 是否开放高年级选课 */
					if ( yesNoFormat(event.getArg('status')) ) {
						propAdvice.setEarlyGraduate( true );
					}
					else {
						propAdvice.setEarlyGraduate( false );
					}
					
					if ( propAdvice.getEarlyGraduate() ) { propAdvice.setRunning( true ); }
					break;
				
				case "Sport":
					
					/* 是否开放高年级选课 */
					if ( yesNoFormat(event.getArg('status')) ) {
						propAdvice.setSport( true );
					}
					else {
						propAdvice.setSport( false );
					}
					
					if ( propAdvice.getSport() ) { propAdvice.setRunning( true ); }
					break;
				
			}
			
			sql = "	UPDATE
						t_choose_turn ct
					SET
						ct.turn_prop = :turnProp 
					WHERE
						ct.ct = :ct ";
			
			queryObj = new Query(datasource = application.dnsMaster);
			queryObj.addParam(name = "ct", value = event.getArg("CT"), cfsqltype = "cf_sql_char");
			queryObj.addParam(name = "turnProp", value = propAdvice.stringProperty(), cfsqltype = "cf_sql_varchar");
			queryObj.execute(sql = sql);
			
			structInsert(response, "Running", propAdvice.getRunning());
			
			structInsert(response, "ProgramTask", propAdvice.getProgramTask());
			structInsert(response, "CommonTask", propAdvice.getCommonTask());
			structInsert(response, "Retaking", propAdvice.getRetaking());
			structInsert(response, "Assist", propAdvice.getAssist());
			structInsert(response, "Secondary", propAdvice.getSecondary());
			structInsert(response, "FixUp", propAdvice.getFixUp());
			structInsert(response, "EarlyGraduate", propAdvice.getEarlyGraduate());
			structInsert(response, "Sport", propAdvice.getSport());
			
		}
		
	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>